{extend name="base"/}
{block name="resources"}
{/block}
{block name="body"}

<!-- 搜索框 -->
<div class="single-filter-box">

    <div class="layui-form">
        <div class="layui-input-inline">
            <input type="text" name="search" placeholder="请输入商品名称" class="layui-input" autocomplete="off">
            <button type="button" class="layui-btn layui-btn-primary" lay-filter="search" lay-submit>
                <i class="layui-icon">&#xe615;</i>
            </button>
        </div>
    </div>
</div>


<!-- 列表 -->
<table id="good_list" lay-filter="good_list"></table>


<!-- 商品 -->
<script type="text/html" id="goodIntro">
    <div class="table-title">
        <div class="title-pic">
            {{# if(d.sku_image){ }}
            <img layer-src src="{{ns.img(d.sku_image.split(',')[0],'small')}}"/>
            {{# } }}
        </div>
        <div class="title-content">
            <a href="javascript:;" class="multi-line-hiding text-color-sub">{{d.sku_name}}</a>
        </div>
    </div>
</script>


{/block}
{block name="script"}
<script>
    var form, table, laytpl;

    layui.use(['form', 'laytpl'], function () {
        form = layui.form;
        laytpl = layui.laytpl;
        form.render();

        table = new Table({
            elem: '#good_list',
            url: '{:addon_url("shop/goods/membergoodsbrowse")}',
            async: false,
            where: {'member_id': "{$member_id}"},
            parseData: function (res) {
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.count,
                    "data": res.data.list,
                };
            },
            cols: [
                [{
                    title: '商品',
                    unresize: 'false',
                    width: '30%',
                    templet: '#goodIntro'
                }, {
                    field: 'price',
                    title: '商品价格',
                    unresize: 'false',
                    width: '10%',
                    align: 'left',
                    templet: function (data) {
                        return '￥<span class="goods-price">' + data.price + '</span>'
                    }
                }, {
                    title: '商品状态',
                    unresize: 'false',
                    width: '10%',
                    align: 'left',
                    templet: function (data) {
                        return data.goods_state == 1 ? '正常' : '下架';
                    }
                }, {
                    title: '浏览量',
                    unresize: 'false',
                    width: '10%',
                    align: 'left',
                    templet: function (data) {
                        return data.click_num;
                    }
                }, {
                    title: '浏览时间',
                    unresize: 'false',
                    width: '20%',
                    align: 'left',
                    templet: function (data) {
                        return ns.time_to_date(data.browse_time);
                    }
                }]
            ]
        });


        /**
         * 搜索功能
         */
        form.on('submit(search)', function (data) {
            table.reload({
                page: {
                    curr: 1
                },
                where: data.field
            });
        });
    });


</script>
{/block}